/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tpdisenio2009.mvp.presenter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import tpdisenio2009.Tpdisenio2009App;
import tpdisenio2009.mvp.display.MainAdministratorView;

/**
 *
 * @author DeuterioX
 */
public class MainAdministratorPresenter extends DefaultPresenter<MainAdministratorView> {

    private ActionListener closeSessionListener;

    public MainAdministratorPresenter( MainAdministratorView view ) {
        super( view );

        bind();
    }

    public void bind() {

        closeSessionListener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if( showConfirmation() ) {
                    Tpdisenio2009App.loggedUser = null;
                    System.exit(0);
                }
            }
        };
        getView().addCloseSessionListener(closeSessionListener);

    }

    public void unbind() {
        if ( closeSessionListener != null )
            getView().removeCloseSessionListener(closeSessionListener);
    }

    private boolean showConfirmation() {
        return getView().showConfirmation( "¿Está seguro que desea cerrar la sesión?"  );
    }

}
